#include "delivery_person_module.h"
#include <map>
#include <iostream>

// 接受订单（自动创建配送员记录并添加订单）
bool DeliveryPersonModule::acceptOrder(int delivery_person_id, int order_id) {
    deliveryOrders[delivery_person_id][order_id] = true;
    std::cout << "订单 " << order_id << " 已被配送员 " << delivery_person_id << " 接受" << std::endl;
    return true;
}

// 交付订单（直接从映射中移除订单）
bool DeliveryPersonModule::deliverOrder(int delivery_person_id, int order_id) {
    auto& orders = deliveryOrders[delivery_person_id];
    auto it = orders.find(order_id);
    
    if (it != orders.end()) {
        orders.erase(it);
        std::cout << "订单 " << order_id << " 已成功交付" << std::endl;
        return true;
    }
    
    std::cerr << "交付失败：未找到订单 " << order_id << std::endl;
    return false;
}

// 查看订单（直接返回映射中的订单列表）
bool DeliveryPersonModule::viewOrders(int delivery_person_id, std::map<int, bool>& orders_map) {
    auto it = deliveryOrders.find(delivery_person_id);
    if (it != deliveryOrders.end()) {
        orders_map = it->second; // 直接返回订单映射
        return true;
    }
    return false; // 配送员无订单记录
} 